<template>
	<view :data-theme="themeStyle">
		<view v-show="show">
			<mescroll-uni @getData="getData" refs="mescroll" :size="10" v-if="seckillId && addonIsExit.seckill" @scroll="scroll">
				<block slot="list">
					<view class="seckill-top">
						<ns-adv keyword="NS_SECKILL"></ns-adv>
						<text v-if="ident" class="seckill-expire-time">距本次活动结束还剩<text class="ns-text-color">{{hour}}</text>:<text class="ns-text-color">{{minute}}</text>:<text class="ns-text-color">{{second}}</text></text>
						<!-- <text v-else class="seckill-expire-time">本场活动已结束，请敬情期待下场活动。</text> -->
					</view>
					<scroll-view class="seckil-nav" scroll-with-animation :scroll-into-view="'a' + seckillId" :scroll-x="true">
						<!-- active 是选中之后的样式 -->
						<view class="nav-item" :id="'a' + item.seckill_id" :class="seckillId == item.seckill_id ? 'active ns-bg-color' : ''"
						 v-for="(item, key) in timeList" :key="key" @click="ontabtap(item.seckill_id, key)">
							<view class="nav-item-con">
								<text class="nav-title">{{ item.name }}</text>
								<text class="nav-content" :class="seckillId == item.seckill_id ? 'ns-bg-color' : ''" v-if="key > index">敬请期待</text>
								<text class="nav-content" :class="seckillId == item.seckill_id ? 'ns-bg-color' : ''" v-if="key == index && !item.isNow">即将开始</text>
								<text class="nav-content" :class="seckillId == item.seckill_id ? 'ns-bg-color' : ''" v-if="key == index && item.isNow">抢购中</text>
								<text class="nav-content" :class="seckillId == item.seckill_id ? 'ns-bg-color' : ''" v-if="key < index">已结束</text>
							</view>
						</view>
					</scroll-view>
					<view class="seckill-goods" v-if="dataList.length" @click="usedGoods(seckillIndex < index && timeList[index].isNow)">
						<view class="goods-item" v-for="(item, key) in dataList" :key="key" @click="toGoodsDetail(item.id, seckillIndex == index && timeList[index].isNow)">
							<view class="goods-img">
								<image :src="$util.img(item.sku_image, { size: 'mid' })" @error="imageError(key)" mode="aspectFill"></image>
							</view>
							<view class="goods-content">
								<text class="title">{{ item.sku_name }}</text>
								<view class="goods-content-info">
									<text class="del ns-gradient-diy-goods-list" :data-theme="themeStyle">{{ $lang('common.currencySymbol') }}{{ item.price }}</text>
									<view class="goods-content-bottom">
										<view class="present-price">
											<!-- <text class="price-title ns-text-color">秒杀价:</text> -->
											<text class="strong ns-text-color">{{ $lang('common.currencySymbol') }}{{ item.seckill_price }}</text>
											<image :src="$util.img('upload/uniapp/miao.png')" mode="widthFix"></image>
										</view>
										<text class="desc-pin ns-bg-color">立即抢购</text>
									</view>
								</view>
							</view>
						</view>
					</view>

					<view v-if="!dataList.length && showEmpty" style="z-index: 1 !important;">
						<ns-empty :fixed="!1"></ns-empty>
					</view>
				</block>
			</mescroll-uni>
		</view>
		<view class="big-empty" v-show="!show">
			<ns-empty text="当前活动暂未开启"></ns-empty>
		</view>

		<loading-cover ref="loadingCover"></loading-cover>
		<ns-show-toast></ns-show-toast>
	</view>
</template>
<script>
	import list from '../public/js/list.js';
	import nsAdv from '@/components/ns-adv/ns-adv.vue';
	import nsShowToast from '@/components/ns-show-toast/ns-show-toast.vue'
	export default {
		components: {
			nsAdv,
			nsShowToast
		},
		data() {
			return {
				hour: '00',
				minute: '00',
				second: '00',
				ident: false,
				
				showEmpty:false
			};
		},
		onLoad() {
		},
		onShow() {
			// 刷新多语言
			if(!this.addonIsExit.seckill){
				this.$util.showToast({
					title:'商家未开启秒杀',
					mask:true,
					duration:2000
				})
				setTimeout(()=>{
					this.$util.redirectTo('/pages/index/index/index',{},'redirectTo')
				},2000)
				return;
			}
			this.$langConfig.refresh();
			this.getTimeList();
		},
		computed: {
			themeStyle() {
				return 'theme-' + this.$store.state.themeStyle
			},
			addonIsExit(){
				return this.$store.state.addonIsExit
			}
		},
		mixins: [list],
		methods: {}
	};
</script>

<style lang="scss">
	/deep/ uni-page{height: auto;}
	.seckill-top{
		position: relative;
		.seckill-expire-time{
			position: absolute;
			display: flex;
			width: 100%;
			height: 66rpx;
			justify-content: center;
			align-items: center;
			background-color: rgba(255, 255, 255, 0.3);
			color: #fff;
			bottom: 24rpx;
			margin: 0 24rpx;
			font-size: $ns-font-size-base;
			letter-spacing: 1px;
			text{
				background-color: #fff;
				width: 20px;
				height: 20px;
				line-height: 20px;
				text-align: center;
				display: inline-block;
				border-radius: 3px;
				margin-right: 2px;
				margin-left: 2px;
			}
		}
	}
	.seckil-nav {
		white-space: nowrap;
		width: 100%;
		height: 92rpx;
		background: #ffffff;
		margin: 0;

		.nav-item {
			width: 25%;
			height: 100%;
			display: inline-block;
			line-height: 1;

			.nav-item-con {
				width: 100%;
				height: 92rpx;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;

				text {
					line-height: 1;
				}
			}

			.nav-title {
				display: block;
				font-size: $ns-font-size-base;
			}

			.nav-content {
				margin-top: 10rpx;
				font-size: $ns-font-size-x-sm;
				display: inline-block;
				border-radius: 18rpx;
			}
		}

		.nav-item.active {
			.nav-title {
				color: #FFFFFF;
			}

			.nav-content {
				color: #fff;
				margin-top: 8rpx;
			}
		}
	}

	.seckil-nav.active {
		position: fixed;
		left: 0;
		top: 0;
		z-index: 100;
	}

	.seckill-goods {
		margin-top: 20rpx;
		display: flex;
		flex-direction: row;
		flex-wrap: wrap;


		.goods-item {
			overflow: hidden;
			display: flex;
			flex-wrap: wrap;
			justify-content: space-between;
			background-color: #fff;
			border-radius: $ns-border-radius;
			width: 339rpx;
			margin-left: 24rpx;
			padding: $ns-padding;
			box-sizing: border-box;
			border-radius: 10rpx;
			overflow: hidden;
			margin-bottom: $ns-margin;
		}

		.goods-img {
			display: flex;
			justify-content: center;
			align-items: center;
			width: 100%;
			height: 300rpx;
			border-radius: 10rpx;
			overflow: hidden;

			image {
				max-width: 100%;
				max-height: 100%;
			}
		}

		.goods-content {
			width: 100%;
			padding: 22rpx 0 0;
			display: flex;
			flex-direction: column;
			justify-content: space-between;

			.title {
				font-size: $ns-font-size-base;
				overflow: hidden;
				text-overflow: ellipsis;
				display: -webkit-box;
				-webkit-line-clamp: 2;
				-webkit-box-orient: vertical;
				line-height: 1.5;
				color: #000000;
			}

			.goods-content-info {
				width: 100%;
				padding-top: 10rpx;
				line-height: 1;

				.del {
					font-size: $ns-font-size-sm;
					border-radius: 5rpx;
					text-decoration: line-through;
					color: #777777;
				}

				.goods-content-bottom {
					width: 100%;
					display: flex;
					flex-direction: row;
					justify-content: space-between;
					align-items: center;

					.present-price {
						display: flex;
						align-items: center;

						.price-title {
							font-size: $ns-font-size-base;
						}

						.strong {
							font-size: $ns-font-size-lg;
							margin-right: 7rpx;
						}
						image{
							width: 30rpx;
							height: 24rpx;
						}
					}
				}
				.desc-pin{
					display: flex;
					justify-content: center;
					align-items: center;
					font-size: $ns-font-size-x-sm;
					color: #fff;
					padding: 10rpx 12rpx;
					border-radius: 48rpx;
					line-height: 1;
				}
			}
		}
	}

	.empty {
		margin-top: 100rpx;
	}

	.big-empty {
		margin-top: 300rpx;
	}

	.uni-progress-info {
		margin-left: 6rpx;
		font-size: 12px;
		color: #fff;
	}
	.ns-gradient-promotionpages-seckill-list-list{background: linear-gradient(to right, #FE934C, $base-color);}
</style>
